library(gtsummary)
library(fastDummies)
library(janitor)

## ##

rm(list = ls())

## Get data 
## Note that this table requires data that we can only partially make available publicly

sum_dat <- readRDS('data_private/civey_issue_replication.rds')


sum_dat <- fastDummies::dummy_cols(sum_dat, select_columns = c('age', 'educ', 
                                                               'gender', 'treat_categ'),
                                   remove_selected_columns = F) %>%
  clean_names() %>% 
  dplyr::select(one_of('climate', 'economy', 'foreign_pol', 'interior', 'migr', 'soc_pol',
                       'age_18_29_jahrige', 'age_30_39_jahrige',
                       'age_40_49_jahrige', 'age_50_64_jahrige',
                       'age_uber_65_jahrige', 'age_na',
                       'educ_abitur_noch_in_schulischer_ausbildung',
                       'educ_hauptschule_kein_abschluss',
                       'educ_mittlere_reife', 
                       'educ_na',
                       'gender_frauen', 
                       'gender_manner',
                       'treat_categ_none',
                       'treat_categ_schwach',
                       'treat_categ_schwer'))

# create summary

stargazer::stargazer(sum_dat,
                     covariate.labels = c('MIP: Climate/environment',
                                          'MIP: Economy',
                                          'MIP: Foreign policy',
                                          'MIP: Domestic security',
                                          'MIP: Migration',
                                          'MIP: Social policy',
                                          'Age: 18 -- 29',
                                          'Age: 30 -- 39',
                                          'Age: 40 -- 49',
                                          'Age: 50 -- 64',
                                          'Age: 65 and above',
                                          'Age: NA',
                                          'Education: A-levels/still in school',
                                          'Education: High school/no degree',
                                          'Education: High school (10yrs)',
                                          'Education: NA',
                                          'Gender: Female',
                                          'Gender: Male',
                                          'Flooding: none (county-level)',
                                          'Flooding: weak (county-level)',
                                          'Flooding: heavy (county-level)'),
                     label = 'tab:civey_sumstats_issue_sal',
                     title = 'Summary statistics, Civey issue salience survey',
                     omit.summary.stat = c("p25", "p75"))



